package com.xrui.hbase.hashing;

import com.google.common.base.Preconditions;
import com.moz.kiji.delegation.Lookups;
import com.moz.kiji.delegation.NamedProvider;

/**
 * Interface for HBase row key hashing.
 * <p>
 * A HBase row key hasher is configured to generate hashes for HBase row keys.
 * <p>
 * HBase row key hashers are instantiated via {@link Hasher.Factory}.
 * <p>
 * Intended for developers only.
 */
public interface Hasher extends NamedProvider{
    /**
     * Returns the hashes as string.
     * @param string value for hashing
     * @return hashes as string
     */
    String getHashString(String string);
    /**
     * Returns the hashes as long.
     * @param string value for hashing
     * @return hashes as long
     */
    long getHashCode(String string);
    /**
     * Returns the hashes as byte array.
     * @param string value for hashing
     * @return hashes as byte array
     */
    byte[] getHashBytes(String string);
    class Factory {
        /**
         * Creates a new Hasher with specified provider name
         * @param name of the Hasher provider
         * @return new instance of the Hasher
         */
        public static Hasher create(String name) {
            Preconditions.checkNotNull(name);
            return Lookups.getNamed(Hasher.class).lookup(name);
        }
    }
}
